package initzation

import (
	"fmt"
	"goodSrv/global"
	"goodSrv/model/entidy"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

func init() {
	//初始化mysql
	InitMysql()
}

func InitMysql() {
	//初始化mysql
	var err error
	// 参考 https://github.com/go-sql-driver/mysql#dsn-data-source-name 获取详情
	dsn := "root:mysql_DAJCYW@tcp(175.24.164.107:3306)/week3?charset=utf8mb4&parseTime=True&loc=Local"
	global.DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	global.DB.AutoMigrate(new(entidy.Good))
	fmt.Println("mysql数据库初始化成功")
}
